package com.dormitory.manage.controller;

import com.dormitory.manage.pojo.Profession;
import com.dormitory.manage.result.Result;
import com.dormitory.manage.service.ProfessionService;
import com.dormitory.manage.vo.AddProfessionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description ProfessionController
 * @date 2023/4/10 0010 14:26
 */

@RestController
@RequestMapping("profession")
@CrossOrigin
@Slf4j
public class ProfessionController {
    @Resource
    private ProfessionService professionService;

    @GetMapping("getProfessionNameList")
    public Result getProfessionNameList(){
        List<String> professionNames = professionService.getProfessionNames();
        return Result.ok(professionNames);
    }

    @DeleteMapping("removeProfession/{id}")
    public Result removeProfession(@PathVariable Long id){
        boolean result = this.professionService.removeProfession(id);
        if (result) {
            return Result.ok();
        }
        return Result.fail();
    }

    @GetMapping("getProfessionInfo/{id}")
    public Result getProfessionInfo(@PathVariable Long id){
        Profession profession = this.professionService.getProfessionInfo(id);
        return Result.ok(profession);
    }

    @PostMapping("addProfession")
    public Result addProfession(@RequestBody AddProfessionVo addProfessionVo){
        boolean result = this.professionService.addProfession(addProfessionVo);
        if (result) {
            return Result.ok();
        }
        return Result.fail();
    }

    @PostMapping("updateProfession")
    public Result updateProfession(@RequestBody Profession profession){
        boolean result = this.professionService.updateProfession(profession);
        if (result){
            return Result.ok();
        }
        return Result.fail();
    }
}

